﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Passwords.Models
{
    public enum AlphaItemType
    {
        Password,
        GroupHeader
    }

    /// <summary>
    /// Item that either contains a password or a header.
    /// This item is used to show a list of passwords with an alphabetic tile to open a quick jump picker.
    /// </summary>
    public class AlphaItem : Entity
    {

        private AlphaItemType itemType;
        private PasswordContract password;
        private string header;

        public AlphaItem(PasswordContract password)
            : base()
        {
            this.password = password;
            itemType = AlphaItemType.Password;
        }

        public AlphaItem(string header)
            : base()
        {
            this.header = header;
            itemType = AlphaItemType.GroupHeader;
        }

        /// <summary>
        /// Gets if the item contains a pasword, otherwise it is a header.
        /// </summary>
        public bool IsPassword
        {
            get { return itemType == AlphaItemType.Password; }
        }

        /// <summary>
        /// Gets or sets if the item is a password or header.
        /// </summary>
        public AlphaItemType ItemType
        {
            get { return itemType; }
            set
            {
                if (itemType != value)
                {
                    itemType = value;
                    OnPropertyChanged("ItemType");
                    OnPropertyChanged("IsPassword");
                }
            }
        }

        /// <summary>
        /// Gets or sets the password.
        /// </summary>
        public PasswordContract Password
        {
            get { return password; }
            set
            {
                if (password != value)
                {
                    password = value;
                    OnPropertyChanged("Password");
                }
            }
        }

        /// <summary>
        /// Gets or sets the header.
        /// </summary>
        public string Header
        {
            get { return header ?? string.Empty; }
            set
            {
                if (header != value)
                {
                    header = value;
                    OnPropertyChanged("Header");
                }
            }
        }
    }
}
